#include <QCoreApplication>
#include <QMutex>
#include <QList>
#include <QSemaphore>
#include <QDateTime>
#include <QThread>
#include <QDir>
#include <QTextStream>
#include <QDebug>

#define     MSG_DEFAULT                 0x01

class LogMessage {
public:
    int level;
    int type;
    QString message;
};

class Logger : public QThread
{
    Q_OBJECT
public:
    Logger();
    QString init(QString path);
    void write(int msgType = MSG_DEFAULT, const QString &msg = "");
    virtual void run();
    void setRunning(bool running);

private:
    QString createDir(QString path);

signals:
    void print(int type, QString info);

private:
    bool running = true;
    QString runPath;
    QMutex mutex;
    QList<LogMessage> msgList;
    QSemaphore syncSem;
};
